<template>
	<page-meta :page-style="$theme.pageStyle">
		<!-- #ifndef H5 -->
		<navigation-bar :front-color="$theme.navColor" :background-color="$theme.navBgColor" />
		<!-- #endif -->
	</page-meta>
	<z-paging ref="paging" v-model="activityData" @query="queryList" :fixed="false" height="100%" use-page-scroll>
		<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in activityData" :key="item.id" btn-width="120">
			<view class="news-card flex bg-white px-[20rpx] py-[32rpx]" @tap.stop="detail(item.image)">
				<!-- @tap.stop="detail(item.image)" -->
				<view class="mr-[20rpx]" v-if="item.logo">
					<u-image :src="item.logo" width="240" height="180"></u-image>
				</view>
				<view class="news-card-content flex flex-col justify-between flex-1">
					<view class="flex justify-between text-base">
						<view class="news-card-content-title font-bold">{{ item.title }}</view>
						<!-- #ifdef H5 -->
						<wx-open-launch-weapp id="launch-btn" :username="item.old_id" path="pages/index/index">
							<component :is="'script'" v-bind="{ type: 'text/wxtag-template' }">
								<view style="background-color: #5374eb; border-radius: 25rpx; padding: 5rpx 20rpx; color: #fff; margin-left: 35rpx; white-space: nowrap;font-size: 28rpx;">跳转</view>
							</component>
						</wx-open-launch-weapp>
						<!-- #endif -->
						<!-- #ifdef MP-WEIXIN -->
						<view class="tiao" @tap.stop="tiaozhuan(item.appid)">跳转</view>
						<!-- #endif -->
					</view>
					<view class="news-card-content-intro text-gray-400 text-sm mt-[16rpx]">
						{{ item.content }}
					</view>
				</view>
			</view>
		</u-swipe-action>
	</z-paging>
</template>

<script lang="ts" setup>
import { ref, reactive, shallowRef } from 'vue';
import { miniapp } from '@/api/shop';

const paging = shallowRef();

const activityData: any = ref([]);

const queryList = async (pageNo, pageSize) => {
	const { lists } = await miniapp();
	lists.forEach((item: any) => {
		item.show = false;
	});
	activityData.value = lists;
	paging.value.complete(lists);
};

const detail = async (img) => {
	uni.navigateTo({
		url: '/pages/partner/partner_detail?img=' + img
	});
};

const tiaozhuan = async (appid) => {
	uni.navigateToMiniProgram({
		appId: appid, // 填入目标小程序的 appId
		path: '', // 打开的页面路径，如果为空则打开首页
		extraData: {
			// 需要传递给目标小程序的数据
		},
		success(res) {
			// 打开成功的回调
		},
		fail(err) {
			// 打开失败的回调
		}
	});
};
</script>

<style scoped>
.tiao {
	background-color: #5374eb;
	border-radius: 25rpx;
	padding: 5rpx 20rpx;
	color: #fff;
	margin-left: 35rpx;
	white-space: nowrap;
}
</style>
